<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>摇骰子</title>
		<style type="text/css">
			div{
				margin: auto;
				text-align: center;
			}
		</style>
	</head>
	<body>
		<div id="div1">
			<select id="sid">
				<option value="选择大小" id="Nochoose">选择大小</option>
				<option value="大" id="big">大</option>
				<option value="小" id="small">小</option>
			</select>
			<br>
			<img src="img2/1.jpg" id="touzi">
		</div>
		<div id="div2">
			<button type="button" onclick="begin()">开始</button>
		</div>
	</body>
	<script type="text/javascript">
		var play = true;
		var selObj = document.getElementById('sid');
		function begin(){
			if(play){
				play = false;
				var iid = document.getElementById('touzi');
				var num = 0;
				if(selObj.value == '选择大小'){
					alert('请选择大小！')
				}else if(selObj.value == '大' || selObj.value == '小'){
					var a = setInterval(function(){
						var ranNum = RanNum();
						touzi.src = 'img2/' + ranNum + '.jpg';
						num++;
						if(num>10){
							clearInterval(a);
							choose(ranNum);
							play = true;
						}
					},300)
				}
				
			}
		}
		function choose(Num){
			var ChosId = document.getElementById('sid');
			var value = ChosId.options[ChosId.selectedIndex].value;
				if(value == '大'){
					if(Num > 3){
						alert('你赢了！');
					}else{
						alert('你输了');
					}
				}
				if(value == '小'){
					if(Num < 3){
						alert('你赢了！');
					}else{
						alert('你输了');
					}
				}
		}
		function RanNum(){
			while(true){
				var RanNum = Math.floor(Math.random()*6);
				if(RanNum != 0){
					return RanNum;
				}
			}
		}
	</script>
</html>
